package com.cxs.service.impl;

import com.cxs.mapper.RegisteredTypeMapper;
import com.cxs.pojo.RegisteredType;
import com.cxs.service.RegisteredTypeService;
import com.cxs.vo.RegisteredTypeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/*
 * @Author:cxs
 * @Date:2021/10/20  14:44
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@Service
public class RegisteredTypeServiceImpl implements RegisteredTypeService {

    @Autowired
    public RegisteredTypeMapper registeredTypeMapper;

    @Override
    public List<RegisteredTypeVO> findregTypes() {
        List<RegisteredTypeVO> list = new ArrayList<>();
        List<RegisteredType> typeList = registeredTypeMapper.selectByExample(null);

        typeList.forEach(r -> {
            RegisteredTypeVO vo = new RegisteredTypeVO();
            BeanUtils.copyProperties(r, vo);
            list.add(vo);
        });
        return list;
    }

    @Override
    public Double getMoney(Integer registeredId) {
        RegisteredType obj = registeredTypeMapper.selectByPrimaryKey(registeredId);
        return obj != null ? obj.getPrice() : null;
    }
}
